<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Released under the MIT License.
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------

namespace app\app\controller;

use cmf\controller\AdminBaseController;
use think\Db;
use app\admin\model\AdminMenuModel;
use api\wxapp\model\Cart;
class CartController extends AdminBaseController
{
    private $shop_id;
    private $where = array();
    private $params = array();
    public function initialize()
    {
        parent::initialize();
        $sessionAdminId = session('ADMIN_ID');
        if($sessionAdminId !== 1){
            //说明是店铺登陆
            $idarr = db::name('app_shop')->alias('t1')
                ->join('app_shopgoods t2','t2.shop_id = t1.id')
                ->where('t1.admin_id',$sessionAdminId)
                ->column('t2.goods_id');
            $this->where[] = ['t2.goods_id','in',$idarr];
        }

        $this->params = $this->param();
        if(isset($this->params['name'])){
            $this->where[] = ['t2.name','like','%'.$this->params['name'].'%'];
        }
        if(isset($this->params['nickname'])){
            $this->where[] = ['t3.nickname','like','%'.$this->params['nickname'].'%'];
        }
    }
    //点赞
    public function index(Cart $cart)
    {
        $query = Cart::alias('t1');
        $query = $cart->leftgoods($query);
        $query = $cart->leftuser($query);
        $query = $cart->leftshop($query);
        
        $query = $query->field('t1.*,t2.name,t3.nickname,t4.name as shopname');

        $list = $query->where($this->where)->paginate(10);
        

        $this->assign('list',$list);
        $list->appends($this->params);  //分页条件
        $this->assign('page', $list->render());
        return $this->fetch();
    }
}
